<template>
  <div class="personal-nav">
    <div class="avatar">
      <img src="@/static/images/common/avatar.jpg" alt="" />
      <div>
        <span>[{{ userName }}]</span>
        <span>[退出登录]</span>
      </div>
    </div>
    <div class="menu">
      <el-menu>
        <el-menu-item-group title="我的交易">
          <el-menu-item
            @click="goto('/personal/personal-orders')"
            :style="{ color: getRoute('personal-orders') ? 'red' : '' }"
            >我的订单</el-menu-item
          >
        </el-menu-item-group>
        <el-menu-item-group title="个人中心">
          <el-menu-item
            @click="goto('/personal/personal-center')"
            :style="{ color: getRoute('personal-center') ? 'red' : '' }"
            >我的中心</el-menu-item
          >
          <el-menu-item
            @click="goto('/personal/address-management')"
            :style="{ color: getRoute('address-management') ? 'red' : '' }"
            >地址管理</el-menu-item
          >
        </el-menu-item-group>
        <el-menu-item-group title="账户管理">
          <el-menu-item
            @click="goto('/personal/personal-info')"
            :style="{ color: getRoute('personal-info') ? 'red' : '' }"
            >个人信息</el-menu-item
          >
          <el-menu-item
            @click="goto('/personal/edit-password')"
            :style="{ color: getRoute('edit-password') ? 'red' : '' }"
            >修改密码</el-menu-item
          >
        </el-menu-item-group>
      </el-menu>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';

export default defineComponent({
  setup() {
    const userName = ref('admin');
    const router = useRouter();
    const route = useRoute();
    return {
      userName,
      router,
      route,
    };
  },
  methods: {
    goto(path: string) {
      this.router.replace({
        path: path,
      });
    },
    getRoute(path: string) {
      return this.route.path.includes(path);
    },
  },
});
</script>

<style lang="scss" scoped>
.personal-nav {
  width: 205px;
  height: 615px;
  margin-right: 34px;
  border: 1px solid #ddd;

  .avatar {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 12px;
    color: #537291;
    padding-bottom: 10px;
    border-bottom: 1px solid red;

    img {
      width: 125px;
      height: 125px;
      border-radius: 50%;
      margin: 10px 0px;
    }

    span {
      cursor: pointer;

      &:nth-child(1) {
        margin-right: 10px;
      }
    }
  }

  .menu {
    ::v-deep .el-menu {
      border: none;
    }
    ::v-deep .el-menu-item-group__title {
      font-size: 16px;
      font-weight: 500;
      color: #303133;
      padding: 0;
      height: 48px;
      line-height: 48px;
      text-align: center;
    }

    ::v-deep .el-menu-item {
      justify-content: center;
      color: #909399;
      padding: 0;
      height: 42px;
    }
  }
}
</style>
